package com.base.utils;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;

/**
 * 将String进行base64编码解码，使用utf-8
 */
public class Base64Util {

	private static final Logger logger = LoggerFactory.getLogger(Base64Util.class);

	private static final String UTF_8 = "UTF-8";

	/**
	 * 对给定的字符串进行base64解码操作
	 */
	public static String decodeData(String inputData) {
        if (null == inputData) {
            return null;
        }
        return new String(Base64.decodeBase64(inputData.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
	}

	/**
	 * 对给定的字符串进行base64加密操作
	 */
	public static String encodeData(String inputData) {
        if (null == inputData) {
            return null;
        }
        return new String(Base64.encodeBase64(inputData.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
	}

	public static void main(String[] args) {
		System.out.println("解码：" + Base64Util.encodeData("123456CustomBase64"));
	}

}